package com.rawm.gen.utils.generate;


import com.rawm.gen.common.Constant;
import com.rawm.gen.entity.Controller;
import com.rawm.gen.support.IGenerate;
import com.rawm.gen.utils.common.StrUtils;
import com.rawm.gen.utils.freemarker.FreeMarkerTemplateUtils;

import java.io.File;

/**
 * 控制层工具类
 *
 * @author hxy
 * @version 1.0.0
 */
public class GenerateController implements IGenerate<Controller> {

    @Override
    public void generateFile(Controller controller) throws Exception {
        final String path = StrUtils.getAbsolutePath()
                + Constant.SRC_PATH
                + StrUtils.package2path(controller.getPackageName() + Constant.DOT);
        final String templateName = "Controller.ftl";
        File pat = new File(path);
        if (!pat.exists()) {
            pat.mkdirs();
        }
        String filePath = path + controller.getEntityName() + "Controller" + Constant.JAVA_SUFFIX;
        File file = new File(filePath);
        FreeMarkerTemplateUtils.generateFile(templateName, file, controller);
        System.out.println("Generate Controller");
    }
}
